package com.zkingsoft.services.distribution.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zkingsoft.dao.distribution.DisClassicCaseDao;
import com.zkingsoft.exception.GlobleException;
import com.zkingsoft.model.distribution.DisClassicCase;
import com.zkingsoft.pojo.PaginationVO;
import com.zkingsoft.services.distribution.DisClassicCaseService;
import com.zkingsoft.util.ModelUtils;

/**
 * This field was generated by Zking.software.Codegen.
 * 
 * @date 2017-07-05 11:36
 */
@Service("disClassicCaseService")
public class DisClassicCaseServiceImpl implements DisClassicCaseService {

	@Autowired
	private DisClassicCaseDao disClassicCaseDao;

	@Override
	public int add(DisClassicCase disClassicCase) {

		return disClassicCaseDao.insert(disClassicCase);

	}

	@Override
	public int batchAdd(List<DisClassicCase> disClassicCaseList) {
		int num = 0;

		int c = 10000;
		int size = disClassicCaseList.size() / c + 1;
		for (int i = 0; i < size; i++) {
			int begin = i * c;
			int end = (i + 1) * c;
			end = end >= disClassicCaseList.size() ? disClassicCaseList.size()
					: end;
			List<DisClassicCase> insertList = disClassicCaseList.subList(begin,
					end);
			num += disClassicCaseDao.batchInsert(insertList);
		}
		return num;

	}

	@Override
	public int modifyByMap(DisClassicCase oldDisClassicCase,
			DisClassicCase newDisClassicCase) {

		if (!ModelUtils.isModified(oldDisClassicCase, newDisClassicCase)) {
			return 1;
		}
		Map<String, Object> modifyMap = null;
		try {
			modifyMap = ModelUtils.comparePojo2Map(oldDisClassicCase,
					newDisClassicCase);
		} catch (Exception e) {
			throw new GlobleException("数据对比失败");
		}
		if (modifyMap.size() > 0) {
			modifyMap.put("caseId", oldDisClassicCase.getCaseId());
			disClassicCaseDao.updateByMap(modifyMap);
		}
		return 1;
	}

	@Override
	public int modifyByModel(DisClassicCase disClassicCase) {

		return disClassicCaseDao.updateByModel(disClassicCase);

	}

	@Override
	public int remove(List<Long> list) {

		return disClassicCaseDao.deleteByIds(list);

	}

	@Override
	public int removeById(Long caseId) {

		return disClassicCaseDao.deleteById(caseId);

	}

	@Override
	public int removeByModel(DisClassicCase disClassicCase) {

		return disClassicCaseDao.deleteByModel(disClassicCase);

	}

	@Override
	public List<DisClassicCase> findInPage(DisClassicCase disClassicCase,
			PaginationVO pageVo) {

		return disClassicCaseDao.selectInPage(disClassicCase, pageVo);

	}

	@Override
	public List<DisClassicCase> findByModel(DisClassicCase disClassicCase) {

		return disClassicCaseDao.selectByModel(disClassicCase);

	}

	@Override
	public int findTotal(DisClassicCase disClassicCase) {

		return disClassicCaseDao.selectTotalRecord(disClassicCase);

	}

	@Override
	public DisClassicCase findById(Long caseId) {

		return disClassicCaseDao.selectById(caseId);

	}

}